package org.monitor.command;

import org.apache.log4j.Logger;
import org.monitor.beans.CommandDTO;
import org.monitor.beans.RequestParam;
import org.monitor.common.Common;
import org.monitor.main.MClient;
import org.monitor.main.Main;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class ExcuteHandleCommand implements Job {
	private static Logger logger = Logger.getLogger(ExcuteHandleCommand.class);

	public void execute(JobExecutionContext context) throws JobExecutionException {

		JobDataMap jmap = context.getMergedJobDataMap();
		CommandDTO command = (CommandDTO) jmap.get("command");
		try {
			String result = Common.execCmd(command.getCommand(), command.getLine());
			String url = "http://" + Main.getConfig().getProperty("server.ip") + ":" + Main.getConfig().getProperty("server.port");
			RequestParam param= Common.makeSign(MClient.getRegisterKey());
			param.getParam().put("data", result);
			param.getParam().put("key", command.getKey());
			param.getParam().put("section", command.getSection());
			param.setAction("postData");
			Common.postData(url, param.getParamsForClent());
		} catch (Exception e) {
			logger.error("ExcuteHandleCommand:\t"+ e.getMessage());
		}
	}
}
